const { Service } = require("node-windows");

const svc = new Service({
  name: "socket_server", // 服务名称
  description: "socket_server", // 服务描述
  script: "./index.js", // 启动文件路径
  wait: "1", // 崩溃后重启时间间隔
  grow: "0.25", // 重启时间间隔增长值
  maxRestarts: "40" // 60 秒内最大重启次数
});

svc.on("install", () => {
  svc.start();
  console.log("Install complete.");
});

svc.on("uninstall", () => {
  console.log("Uninstall complete.");
  console.log("The service exists: ", svc.exists);
});

svc.on("alreadyinstalled", () => {
  console.log("This service is already installed.");
});

if (svc.exists) return svc.uninstall();

svc.install();
